<template>
    <div class="zh-archives-edit">
        <div class="classIndex_h">
            <span @click="goBack">我的档案</span>
            <!-- <strong><i>></i>编辑</strong> -->
        </div>

        <div class="file-base-photo">
            <div class="presonPic">
                <img :src="previewImgURL" class="avatar">
                <div>
                    <span class="name-pinyin">
                        <template  v-for="item in basicscList.studystatus">
                            <span v-if="item.id === 1">{{item.field_name}}：</span>
                            <span class="pinyin-edit"  v-if="item.id === 1 || item.id === 2">

                                <template  v-if="isDisabled">
                                    <span  v-if="item.id === 1">{{item.content.content}}</span>
                                    <span  v-if="item.id === 2 && item.content.content">({{item.content.content}})</span>
                                </template>
                                <template v-else>
                                    <input v-if="item.id === 1" type="text" v-model="item.content.content" :disabled="isDisabled">
                                    <input v-if="item.id === 2" type="text" v-model.trim="item.content.content" :disabled="isDisabled">
                                </template>
                               
                            </span>

                        </template>
                    </span>



                    <template v-if="!isDisabled">
                    <template v-for="(item, index) in basicscList.studystatus">
                        <uploader 
                            :ref="'uploader' + (index + 1)"
                            class="uploader-broadcasts"
                            v-if="item.id === 18"
                            :key="index"
                            :options="uploadOptions"
                            :autoStart="true"
                            :file-status-text="statusText"
                            @files-submitted="fileSubmit"
                            @file-removed="fileRemoved"
                            @file-success="fileSuccess"
                            @file-error="fileFail">
                            <uploader-unsupport></uploader-unsupport>
                            <uploader-btn :directory="false" :attrs="attrs" :single="true"><span @click="setPhoto(item, index + 1)">更换照片</span></uploader-btn>
                        </uploader>
                    </template>
                    </template>
                </div>
            </div>

            <template v-for="(item, index) in basicscList.studystatus">
                <div :key="index" v-if="item.id === 16">
                    <img :src="'/images/file-' + statusList[item.content.content ? (item.content.content - 1) : 0] + '.png'">
                    <span>{{item.field_name}}</span>
                </div>
            </template>
        </div>

        <div class="archives-btn">
           <el-button type="text" @click="editBasicsc">编辑</el-button>
       </div>

       <template v-if="!isDisabled">
            <!-- 基础信息 -->
            <template v-if="activeName === '1'">
                <div class="archives-btn">
                    <el-button type="primary" plain @click="goBack(1)">取消</el-button>
                    <el-button type="primary" @click="submitBasicsc">保存</el-button>
                     
                </div>

            </template>
            <!-- 家庭信息 -->
            <template v-if="activeName === '2'">
                <div v-if="familyList.length > 0" class="archives-btn">
                    <el-button type="primary" plain @click="goBack(2)">取消</el-button>
                    <el-button type="primary" @click="submitFamily">保存</el-button>
                </div>
            </template>
            <!-- 来源信息 -->
            <template v-if="activeName === '3'">
                <div class="archives-btn">
                    <el-button type="primary" plain @click="goBack(3)" >取消</el-button>
                    <el-button type="primary" @click="submitSource">保存</el-button>
                </div>
            </template>
            <!-- 其他信息 -->
            <template v-if="activeName === '4'">
                <div class="archives-btn" >
                    <el-button type="primary" plain @click="goBack(4)">取消</el-button>
                    <el-button type="primary" @click="submitOther">保存</el-button>
                </div>
            </template>
        </template>


        <el-tabs v-model="activeName" type="card" @tab-click="changeTab" v-loading="loading.status" :element-loading-text="loading.txt">
            <el-tab-pane label="基础信息" name="1">

                <div class="file-base-info" v-if="Object.keys(basicscList).length != 0">
                    <div>
                        <span>账号：</span>
                        <el-input  v-model="basicscList.user_number" disabled></el-input>
                    </div>
                    <div>
                        <span>用户名：</span>
                        <el-input  v-model="basicscList.user_name" disabled></el-input>
                    </div>
                    <div>
                        <span>学校：</span>
                        <el-input  v-model="basicscList.school_name" disabled></el-input>
                    </div>
                    <div>
                        <span>班级：</span>
                        <el-input  v-model="basicscList.class.rename" disabled></el-input>
                    </div>
                    <div>
                        <span>班主任：</span>
                        <el-input  v-model="basicscList.class.teacher_name" disabled></el-input>
                    </div>

                    <template v-for="(item, index) in basicscList.studystatus">
                        <div :key="index" v-if="item.is_up !== 1">
                            <span>{{item.field_name}}：</span>

                            <template v-if="item.type === 3">
                                <el-radio-group v-model="item.content.content" :disabled="isDisabled">
                                    <template v-for="(item2, index2) in item.field_option">
                                        <el-radio :label="(index2 + 1)" :key="index2">{{item2}}</el-radio>
                                    </template>
                                </el-radio-group>
                            </template>
                            <template v-else-if="item.type === 4">
                                <el-date-picker
                                    v-model="item.content.content"
                                    type="date"
                                    :disabled="isDisabled"
                                    placeholder="选择日期"
                                    format="yyyy-MM-dd"
                                    value-format="yyyy-MM-dd">
                                </el-date-picker>
                            </template>
                            <template v-else-if="item.type === 5">
                                <el-select v-model="item.content.content" :placeholder="'请选择' + item.field_name" :disabled="isDisabled">
                                    <el-option
                                        v-for="(item1, inx1) in item.field_option"
                                        :key="inx1"
                                        :label="item1"
                                        :value="inx1 + 1">
                                    </el-option>
                                </el-select>
                            </template>
                            <template v-else>
                                <div v-if="item.id === 11">
                                    <el-input  
                                        :maxLength="11"
                                        :disabled="isDisabled"
                                        :class="errorTitle.telTip ? 'error-tips-info' : ''"
                                        @blur="setNumber(item)"
                                        v-model="item.content.content">
                                    </el-input>
                                    <div style="color: red; font-size: 12px;">{{errorTitle.telTip}}</div>
                                </div>
                                <div v-else-if="item.id === 12">
                                    <el-input  
                                        :maxLength="18"
                                        :disabled="isDisabled"
                                        :class="errorTitle.cardTip ? 'error-tips-info' : ''"
                                        @blur="validatedCard(item)"
                                        v-model="item.content.content">
                                    </el-input>
                                    <div style="color: red; font-size: 12px;">{{errorTitle.cardTip}}</div>
                                </div>
                                
                                <el-input  
                                    v-else
                                    :type="item.type === 6 ? 'textarea' : 'text'" 
                                    :rows="4"
                                    :disabled="isDisabled"
                                    v-model="item.content.content">
                                </el-input>
                            </template>
                        </div>
                    </template>
                </div>
                
            </el-tab-pane>

            <el-tab-pane label="家庭信息" name="2">

                <div class="file-family-info">
                    <div class="file-family-info-title">
                        <template  v-if="familyList.length > 0">
                            <template v-for="(item, inx) in familyList.filter(item => item.user_id !== 0)">
                                <div 
                                    :class="(isFamilyBounded === true) && (familyBoundedIndex === inx) ? 'family-info-active' : ''" 
                                    :key="item.id" 
                                    @click="setStyleActive(inx, true)">
                                    <span>家长{{inx + 1}}</span>
                                </div>
                            </template>

                            <template v-for="(item2, inx2) in familyList.filter(item2 => item2.user_id === 0)">
                                <div 
                                    :class="(isFamilyUnbounded === false) && (familyUnboundedIndex === inx2) ? 'family-info-active' : ''" 
                                    :key="item2.id" 
                                    @click="setStyleActive(inx2, false)">
                                    <span>成员{{inx2 + 1}}</span>
                                    <i class="el-icon-remove" v-if="!isDisabled" @click.stop="removeMenber(inx2)"></i>
                                </div>
                            </template>
                        </template>
                        <span  @click="newMember">添加新成员</span>
                    </div>

                    <div class="file-family-info-box"  v-if="familyList.length > 0">
                        <div 
                            :class="(isFamilyBounded === true) && (familyBoundedIndex === index) ? 'family-info-active' : ''"
                            v-for="(item, index) in familyList.filter(item => item.user_id !== 0)" 
                            @click="setStyleActive(index, true)"
                            :key="item.id">
                            <div>
                                <span>家长{{index + 1}}账号：</span>
                                <el-input  v-model="item.number" disabled></el-input>
                            </div>
                            <div>
                                <span>用户名：</span>
                                <el-input  v-model="item.username" disabled></el-input>
                            </div>

                            <template v-for="(item1, inx1) in item.field">
                                <div :key="inx1">
                                    <span>{{item1.field_name}}：</span>

                                    <template v-if="item1.type === 3">
                                        <el-radio-group v-model="item1.content.content" :disabled="isDisabled">
                                            <template v-for="(item2, index2) in item1.field_option">
                                                <el-radio :label="(index2 + 1) + ''" :key="index2">{{item2}}</el-radio>
                                            </template>
                                        </el-radio-group>
                                    </template>
                                    <template v-else>
                                        <template v-if="isDisabled">
                                            <el-input  v-model="item1.content.content" disabled></el-input>
                                        </template>
                                        <template v-else>
                                            <div v-if="item1.id === 50">
                                                <el-input  
                                                    :maxLength="18"
                                                    :disabled="isDisabled"
                                                    :class="errorTitle2[index] ? 'error-tips-info' : ''"
                                                    @input="setNumber2(item1, index)"
                                                    v-model="item1.content.content">
                                                </el-input>
                                                <div style="color: red; font-size: 12px;">{{errorTitle2[index]}}</div>
                                            </div>

                                            <el-input  
                                                v-else
                                                v-model="item1.content.content" 
                                                :disabled="item1.id === 22 ? true : false">
                                            </el-input>
                                        </template>
                                    </template>
                                </div>
                            </template>
                        </div>

                        <div 
                            :class="(isFamilyUnbounded === false) && (familyUnboundedIndex === inx2) ? 'family-info-active' : ''" 
                            v-for="(item, inx2) in familyList.filter(item => item.user_id === 0)" 
                             @click="setStyleActive(inx2, false)"
                            :key="item.id">
                            <template v-for="(item1, inx1) in item.field">
                                <div :key="inx1">
                                    <span>{{item1.field_name}}：</span>

                                    <template v-if="item1.type === 3">
                                        <el-radio-group v-model="item1.content.content" :disabled="isDisabled">
                                            <template v-for="(item2, index2) in item1.field_option">
                                                <el-radio :label="(index2 + 1) + ''" :key="index2">{{item2}}</el-radio>
                                            </template>
                                        </el-radio-group>
                                    </template>
                                    <template v-else>
                                        <div v-if="item1.id === 22">
                                            <el-input  
                                                :maxLength="11"
                                                :disabled="isDisabled"
                                                :class="errorTitle1[inx2] ? 'error-tips-info' : ''"
                                                @input="setNumber1(item1, inx2)"
                                                v-model="item1.content.content">
                                            </el-input>
                                            <div style="color: red; font-size: 12px;">{{errorTitle1[inx2]}}</div>
                                        </div>

                                        <div v-else-if="item1.id === 50">
                                            <el-input  
                                                :maxLength="18"
                                                :disabled="isDisabled"
                                                :class="errorTitle2[inx2] ? 'error-tips-info' : ''"
                                                @input="setNumber2(item1, inx2)"
                                                v-model="item1.content.content">
                                            </el-input>
                                            <div style="color: red; font-size: 12px;">{{errorTitle2[inx2]}}</div>
                                        </div>

                                        <el-input  v-else v-model="item1.content.content" :disabled="isDisabled"></el-input>
                                    </template>
                                </div>
                            </template>
                        </div>
                    </div>
                </div>

                
            </el-tab-pane>

            <el-tab-pane label="来源信息" name="3">

                <div class="file-source-info">
                    <template v-for="(item, sindex) in sourceList">
                        <div :key="sindex" v-if="item.is_up !== 1">
                            <span>{{item.field_name}}：</span>

                            <template v-if="item.type === 4">
                                <el-date-picker
                                    v-model="item.content.content"
                                    type="date"
                                    :disabled="isDisabled"
                                    placeholder="选择日期"
                                    format="yyyy-MM-dd"
                                    value-format="yyyy-MM-dd">
                                </el-date-picker>
                            </template>
                            <template v-else-if="item.type === 5">
                                <el-select v-model="item.content.content" :placeholder="'请选择' + item.field_name" :disabled="isDisabled">
                                    <el-option
                                        v-for="(item1, inx1) in item.field_option"
                                        :key="inx1"
                                        :label="item1"
                                        :value="inx1 + 1">
                                    </el-option>
                                </el-select>
                            </template>
                            <template v-else>
                                <el-input  
                                    :type="item.type === 6 ? 'textarea' : 'text'" 
                                    :rows="4"
                                    :disabled="isDisabled"
                                    v-model="item.content.content">
                                </el-input>
                            </template>
                        </div>
                    </template>
                </div>
                
            </el-tab-pane>

            <el-tab-pane label="其他信息" name="4">

                <div class="file-other-info">
                    <template v-for="(item, oindex) in otherList">
                        <div :key="oindex" v-if="item.is_up !== 1">
                            <span>{{item.field_name}}：</span>

                            <template v-if="item.type === 3">
                                <el-radio-group v-model="item.content.content" @change="changeRadioVal(oindex)" :disabled="isDisabled">
                                    <template v-for="(item2, index2) in item.field_option">
                                        <el-radio :label="(index2 + 1) " :key="index2">{{item2}}</el-radio>
                                    </template>
                                </el-radio-group>
                            </template>
                            <template v-else>
                                <template v-if="isDisabled">
                                    <el-input  v-model="item.content.content" disabled></el-input>
                                </template>
                                <template v-else>
                                    <el-input  
                                        v-model="item.content.content" 
                                        :disabled="otherList[oindex -1].content.content == 1 ? false : true">
                                    </el-input>
                                </template>
                            </template>
                        </div>
                    </template>
                </div>
                
            </el-tab-pane>
        </el-tabs>
    </div>
</template>
<script>
export default {
    data() {
        return {
            uploadOrNot: false, //是否已经上传
            selectFileOrNot: false, //是否选中文件
            selectFileShow: true, //是否显示选择文件按钮
            isRealName: true, // 是否编辑真实姓名
            isPinyin: true, // 是否编辑姓名拼音
            uploadRetryTimes: 100, //文件最大重传次数
            familyBindLen: 0, // 家庭信息绑定账号的数量
            previewImgURL: '',
            activeName: "1",
            realName: '', // 填写真实姓名
            user_level: sessionStorage.getItem('user_level') == 'undefined' ? undefined : JSON.parse(sessionStorage.getItem('user_level')), /*判断当前登录会员是否教育局 */
            statusList: ['normal', 'warning', 'warning', 'warning', 'warning', 'graduated'], // 状态列表 0正常 || 1异动 || 5已毕业
            attrs: { accept: ["image/*"] },
            loading:{
                status: false,
                txt: '获取数据...',
            },
            uploadOptions: {
                target: this.BASE_URL + "/api/resource/res_upload",
                testChunks: false,
                headers: { Authorization: `Bearer ` + this.$g.access_token }
            },
            statusText: {
                success: "上传成功",
                error: "上传出错",
                uploading: "正在上传...",
                paused: "暂停",
                waiting: "等待上传"
            },
            uploadInfo: {
                file_name: '',
                file_path: '',
                file_size: 0
            },
            basicscList: {}, // 基础信息
            _basicscList: {}, // 默认基础信息
            familyList: {}, // 家庭信息
            _familyList: {}, // 默认家庭信息
            sourceList: {}, // 来源信息
            _sourceList: {}, // 默认来源信息
            otherList: {}, // 其他信息
            photoItem: null, // 图片上传的对象
            photoID: '', // 图片上传组件 ref
            isDisabled: true, // 教育局 -- 页面不可编辑
            isFamilyBounded: true, // 家庭信息 -- 绑定
            familyBoundedIndex: 0, // 家庭信息 -- 绑定下标
            isFamilyUnbounded: null, // 家庭信息 -- 未绑定
            familyUnboundedIndex: -1, // 家庭信息 -- 未绑定下标
            errorTitle: { // 错误提示
                telTip: '',
                cardTip: '',
            },
            errorTitle1: [], // 电话错误提示
            errorTitle2: [], // 身份证错误提示
        };
    },
    created() {
        for (let i=1; i<=4; i++) {
            this.getList(i);
        }

        if (this.$route.query.level === 'detail' && this.user_level === 0) {
            this.isDisabled = true;
        }
    },
    methods: {
        editBasicsc(){
            this.isDisabled = false
        },
        /**
         * 设置样式高亮
         * @param {Number} index 对象下标
         * @param {Number} key 是否绑定
         */
        setStyleActive(index, key) {
            if (key === true) {
                this.isFamilyBounded = key;
                this.familyBoundedIndex = index;
                this.isFamilyUnbounded = null;
                this.familyUnboundedIndex = -1;
            } else {
                this.isFamilyBounded = null;
                this.familyBoundedIndex = -1;
                this.isFamilyUnbounded = key;
                this.familyUnboundedIndex = index;
            }
        },
        /**
         * 根据 radio 的值清空数据
         * @param {Number} index 对象的下标
         */
        changeRadioVal(index) {

                if (this.otherList[index + 1] && this.otherList[index + 1].type === 1 && this.otherList[index].content.content == 2) {
                  this.otherList[index + 1].content.content = null;
              }
        },
        /**
         * 验证身份证
         * @param {Object} obj 当前对象
         */
        validatedCard(obj) {
            if (is_empty(obj.content.content)) {
                this.errorTitle.cardTip = '';
                return false;
            }

            let _temp = deep_clone(obj.content.content) + '';
            //身份证正则表达式(15位)
            let isIDCard1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
            //身份证正则表达式(18位)
            let isIDCard2 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;
            // 身份证正则合并
            let isIDCard3 = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/;

            
            if (!isIDCard2.test(_temp)) {
                this.errorTitle.cardTip = '请输入正确的身份证号';
            } else {
                this.errorTitle.cardTip = '';
            }
        },
        /**
         * 验证身份证
         * @param {Object} obj 当前对象
         * @param {Number} inx 对象下标
         */
        setNumber2(obj, inx) {
            if (is_empty(obj.content.content)) {
                this.errorTitle2[inx] = '';
                return false;
            }

            let _temp = deep_clone(obj.content.content) + '';
            //身份证正则表达式(15位)
            let isIDCard1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
            //身份证正则表达式(18位)
            let isIDCard2 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;
            // 身份证正则合并
            let isIDCard3 = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/;

            
            let isIDCard4 = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/

                      
              if (!isIDCard4.test(_temp)) {
                  this.errorTitle2[inx] = '请输入正确的身份证号';
              } else {
                  this.errorTitle2[inx] = '';
              }
        },
        /**
         * 输入框设置长度
         * @param {Object} obj 当前对象
         */
        setNumber(obj) {
            if (is_empty(obj.content.content)) {
                this.errorTitle.telTip = '';
                return false;
            }

            let _temp = deep_clone(obj.content.content) + '';
            let reg1 = /^1[3456789]\d{9}$/;

            if (!reg1.test(_temp)) {
                this.errorTitle.telTip = '请输入正确的联系方式';
            } else {
                this.errorTitle.telTip = '';
            }
        },
        /**
         * 输入框设置长度
         * @param {Object} obj 当前对象
         * @param {Number} inx 对象下标
         */
        setNumber1(obj, inx) {
            if (is_empty(obj.content.content)) {
                this.errorTitle1[inx] = '';
                return false;
            }

            let _temp = deep_clone(obj.content.content) + '';
            let reg1 = /^1[3456789]\d{9}$/;

            if (!reg1.test(_temp)) {
                this.errorTitle1[inx] = '请输入正确的联系方式';
            } else {
                this.errorTitle1[inx] = '';
            }
        },
        /**
         * 设置上传插件的ref和当前对象
         * @param {Object} item 当前点击的对象
         * @param {Number} index 当前点击的index
         */
        setPhoto(item, index) {
            this.photoItem = item;
            this.photoID = 'uploader' + index;
        },
        /**
         * 获取信息
         * @param {Number} key 1基础信息 || 2家庭信息 || 3来源信息 || 4其他信息
         */
        getList(key) {
            this.loading.status = true;
            
            let success = (res => {
                this.loading.status =  false;
                
                switch(key) {
                    case 1:
                        this.basicscList = deep_clone(res.data);
                        this._basicscList = deep_clone(res.data);


                        if (!is_empty(res.data.studystatus)) {
                            res.data.studystatus.forEach(item => {
                                if (item.id === 18) {
                                    if (item.content.content != null) {
                                        this.previewImgURL = this.BASE_URL + deep_clone(item.content.content);
                                    }
                                }
                            })
                        }
                        break;
                    case 2:
                        this.familyList = deep_clone(res.data);
                        this._familyList = deep_clone(res.data);
                        this.familyBindLen = this.familyList.filter(item => item.user_id !== 0).length;
                        break;
                    case 3:
                        this.sourceList = deep_clone(res.data);
                        this._sourceList = deep_clone(res.data);
                        break;
                    case 4:
                        this.otherList = deep_clone(res.data);
                        this._otherList = deep_clone(res.data);
                        break;
                }
            });
            let params = {
                user_id: this.$g.user_id,
                from_type: key,
            }
            
            this.$ajax.get('api/studystatus/studystatus_info', {params, func: {success: success}})
        },
        /**
         * 修改真实姓名
         * @param {String} str 真实姓名
         * @param {Object} obj 基础信息对象
         */
        changeRealName(str, obj) {
            if (str) {
                obj.forEach(item => {
                    if (item.id === 2) {
                        // item.content.content = this.$pinyin(str, {filterChinese: true, noTone: true});
                    }
                })
            }

            this.isRealName = true;
        },
        /**
         * 修改姓名拼音
         */
        changeSpell() {
            this.isPinyin = true;
        },
        /**
         * 删除新增成员
         * @param {Number} inx familyList 对象下标
         */
        removeMenber(inx) {
            let yes = (res => {
                this.familyList.splice(inx + this.familyBindLen, 1);
            })
            let cancel = (res => {})
            
            this.e_confirm({yes: yes, cancel: cancel, txt: '是否删除当前家庭成员模块？'});
        },
        /**
         * 家庭信息 -- 添加新成员
         */
        newMember() {
            this.familyList.push({
                number: '',
                user_id: 0,
                username: '',
                field: [
                   {id: 19, field_name: '真实姓名', field_option: '', type: 1, content: {content: null}},
                   {id: 20, field_name: '关系', field_option: '', type: 1, content: {content: null}},
                   {id: 21, field_name: '是否监护人', field_option :['是', '否'], 'type': 3, content: {content: null}},
                   {id: 22, field_name: '电话', field_option: '', type: 1, content: {content: null}},
                   {id: 23, field_name: '职务', field_option: '', type: 1, content: {content: null}},
                   {id: 24, field_name: '单位地址', field_option: '', type: 1, content: {content: null}},
                   {id: 25, field_name: '国籍', field_option: '', type: 1, content: {content: null}},
                   {id: 26, field_name: '民族', field_option: '', type: 1, content: {content: null}},
                   {id: 27, field_name: '籍贯', field_option: '', type: 1, content: {content: null}},
                   {id: 28, field_name: '户籍所在地', field_option: '', type: 1, content: {content: null}},
                   {id: 50, field_name: '身份证号', field_option: '', type: 1, content: {content: null}}
                ] 
            })
        },
        /**
         * 保存基础信息
         */
        submitBasicsc() {
            if (this.errorTitle.telTip !== '' || this.errorTitle.cardTip !== '') {
                return false;
            }

            let param = {arr: []};
            param.arr['user_id'] = this.$g.user_id;
            param.arr['basic'] = [];

            this.basicscList.studystatus.forEach(item => {
                let _arr = {
                    field_id: item.id,
                    content: item.content.content
                }

                param.arr['basic'].push(_arr);
            })

            const success = (res => {
                this.isDisabled = true;
                this.$message.success(res.msg);
                // this.getList(+this.activeName);
            })

            this.$ajax.post("api/studystatus/studystatus_operation", param, {func: {success: success}});
        },
        /**
         * 保存家庭信息
         */
        submitFamily() {
            let len1 = this.errorTitle1.length;
            if (len1 > 0) {
                for (let i=0; i<len1; i++) {
                    if (this.errorTitle1[i] !== '') {
                        return false;
                    }
                }
            }

            let len2 = this.errorTitle2.length;
            if (len2 > 0) {
                for (let i=0; i<len2; i++) {
                    if (this.errorTitle2[i] !== '') {
                        return false;
                    }
                }
            }

            let param = {arr: []};
            param.arr['user_id'] = this.$g.user_id;
            param.arr['family'] = [];

            this.familyList.forEach((item, index) => {
                param.arr['family'][index] = [];
                param.arr['family'][index]['family_id'] = item.user_id;

                item.field.forEach(item1 => {
                    param.arr['family'][index].push({
                        field_id: item1.id,
                        content: item1.content.content
                    })
                })
            })

            const success = (res => {
                this.$message.success(res.msg);
            })

            this.$ajax.post("api/studystatus/studystatus_operation", param, {func: {success: success}});
        },
        /**
         * 保存来源信息
         */
        submitSource() {
            let param = {arr: []};
            param.arr['user_id'] = this.$g.user_id;
            param.arr['cource'] = [];

            this.sourceList.forEach(item => {
                let _arr = {
                    field_id: item.id,
                    content: item.content.content
                }

                param.arr['cource'].push(_arr);
            })

            const success = (res => {
                this.$message.success(res.msg);
            })

            this.$ajax.post("api/studystatus/studystatus_operation", param, {func: {success: success}});
        },
        /**
         * 保存其他信息
         */
        submitOther() {
            let param = {arr: []};
            param.arr['user_id'] = this.$g.user_id;
            param.arr['other'] = [];

            this.otherList.forEach(item => {
                let _arr = {
                    field_id: item.id,
                    content: item.content.content
                }

                param.arr['other'].push(_arr);
            })

            const success = (res => {
                this.$message.success(res.msg);
            })

            this.$ajax.post("api/studystatus/studystatus_operation", param, {func: {success: success}});
        },
   
        /**
         * 切换tab标签页
         */
        changeTab(tab, event) {},

        /**
         * 判断两个对象是否相等
         * @param {Object} a 默认对象 
         * @param {Object} b 要比较的对象
         */
        isObjectValueEqual(a, b) {
            let aProps = Object.getOwnPropertyNames(a);
            let bProps = Object.getOwnPropertyNames(b);
        
            if (aProps.length != bProps.length) {
                return false;
            }

            for (let i=0; i<aProps.length; i++) {
                let propName = aProps[i];
                let propA = a[propName];
                let propB = b[propName];

                // propA 和 propB 都为空或 null 的时候，默认相等
                if ((propA === '' || propA === null) && (propB === '' || propB === null)) {
                    continue;
                } else {
                    if (propA != propB) {
                        if (Object.prototype.toString.call(propA) == '[object Object]' || Object.prototype.toString.call(propA) == '[object Array]') {
                            if (this.isObjectValueEqual(propA, propB)) {
                                continue
                            } else {
                                return false;
                            }
                        } else {
                            return false;
                        }
                    }
                }
            }

            return true;
        },
        /**
         * 返回上一页
         * @param {Number} key 相对应模块
         */
        goBack(key) {
            let flag = false;

            switch(key) {
                case 1:
                    flag = this.isObjectValueEqual(this._basicscList, deep_clone(this.basicscList));
                    break;
                case 2:
                    flag = this.isObjectValueEqual(this._familyList, deep_clone(this.familyList));
                    break;
                case 3:
                    flag = this.isObjectValueEqual(this._sourceList, deep_clone(this.sourceList));
                    break;
                case 4:
                    flag = this.isObjectValueEqual(this._otherList, deep_clone(this.otherList));
                    break;
            }

            if (!flag) {
                let yes = (res => {
                    for (let i=1; i<=4; i++) {
                        this.getList(i);
                    }
                    this.isDisabled = true;
                })
                let cancel = (res => {})
                    
                this.e_confirm({yes: yes, cancel: cancel, txt: '你有数据未保存，是否确定取消？'});
            } else {
                for (let i=1; i<=4; i++) {
                    this.getList(i);
                }
                this.isDisabled = true;
                // this.$router.go(-1);
            }
        },
        /**
         * 更换头像成功
         */
        fileSuccess(rootFile, file, message, chunk) {
           var mess = JSON.parse(message);
            mess = handleResponseData(mess)

            if (parseInt(mess.data.status) === 1) {
                this.uploadOrNot = true;
                // this.uploadInfo.file_name = mess.data.file_name;
                // this.uploadInfo.file_path = mess.data.file_path;
                // this.uploadInfo.post_fix = mess.data.post_fix;
                this.photoItem.content.content = mess.data.file_path;

            }
        },
        /**
         * 更换头像失败
         */
        fileFail(rootFile, file, message, chunk) {
            let mess = eval("(" + message + ")");

            if (parseInt(mess.error) === 401 && this.uploadRetryTimes > 0) {
                let callbcak = data => {
                    this.uploadRetryTimes--;
                    this.$refs[this.photoID][0].uploader.retry(file);
                };
                this.get_access_token(callbcak);
            } else {
                this.$message.error(mess.msg);
            }
        },
        /**
         * 过滤文件格式
         */
        fileSubmit(files, fileList, event) {
            for (let i=0; i<fileList.length; i++) {
                if (fileList[i].fileType.indexOf("image/") === -1) {
                    this.$message.warning("只允许上传图片格式的文件");
                    this.$refs[this.photoID][0].uploader.removeFile(fileList[i]);
                } else if (fileList[i].size > 2048000) {
                    this.$message.warning("只允许上传2M以内的文件");
                    this.$refs[this.photoID][0].uploader.removeFile(fileList[i]);
                } else {
                    if (this.$refs[this.photoID][0].uploader.fileList.length > 1) {
                        //删除第一张图片
                        this.$refs[this.photoID][0].uploader.removeFile(
                            this.$refs[this.photoID][0].uploader.fileList[0]
                        );
                    }

                    this.previewImgURL = window.URL.createObjectURL(fileList[i].file);
                    this.uploadInfo.file_size = fileList[i].size;
                    this.selectFileOrNot = true;
                    this.selectFileShow = false;
                }
            }
        },
        /**
         * 移除文件
         */
        fileRemoved(file) {
            this.selectFileOrNot = false;
            this.selectFileShow = true;
        }
    }
};
</script>
